第十一題 UVa10696
#include<iostream>
using namespace std;
long f91(long number)
{
if(number<=100)
return f91(f91(number+11));
else
return number-10;
}
int main()
{
long N;
while(cin>>N)
{
if(N==0)
break;
cout<<"f91("<<N<<") = "<<f91(N)<<endl;
}
}
第十二題 UVa10783
#include<iostream>
using namespace std;
int main()
{
int tc;
cin>>tc;
for(int test=1;test<=tc;test++)
{
int a,b,sum=0;
cin>>a>>b;
if(a%2==0)
a++;
if(b%2==0)
b--;
for(int i=a;i<=b;i+=2)
{
sum+=i;
}
cout<<"Case "<<test<<": "<<sum<<endl;
}
}
第十三題 UVa10789
#include<iostream>
using namespace std;
bool is_prime(int num)
{
int i;
if(num==1)
return false;
else
{
for(i=2;i<num;i++)
{
if(num%i==0)
return 0;
}
}
return true;
}
int main()
{
int tc;
cin>>tc;
for(int test=1;test<=tc;test++)
{
int frequency[123]={0};
string word,ans="";
cin>>word;
for(int i=0;i<word.length();i++)
frequency[word[i]]++;
for(int i=48;i<58;i++)
{
if(is_prime(frequency[i]))
ans+=(char)i;
}
for(int i=65;i<91;i++)
{
if(is_prime(frequency[i]))
ans+=(char)i;
}
for(int i=97;i<123;i++)
{
if(is_prime(frequency[i]))
ans+=(char)i;
}
if(ans=="")
cout<<"Case "<<test<<": empty"<<endl;
else
cout<<"Case "<<test<<": "<<ans<<endl;
}
}
第十四題 UVa10812
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
int tc;
cin>>tc;
while(tc--)
{
int a,b,sum,diff;
cin>>sum>>diff;
a=(sum+diff)/2;
b=sum-a;
if(a<0||b<0||(a+b)!=sum||(abs(a-b))!=diff)
cout<<"impossible"<<endl;
else if(a>b)
cout<<a<<" "<<b<<endl;
else
cout<<b<<" "<<a<<endl;
}
}
第十五題 UVa10878
#include<iostream>
#include<string>
using namespace std;
int main()
{
string word;
while(getline(cin,word))
{
if(word[0]=='_')
continue;
char c=0;
for(int i=1;i<word.length()-1;i++)
{
if(word[i]=='o')
c=c*2+1;
else if(word[i]==' ')
c*=2;
}
cout<<c;
}
}